package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.query.AttendanceQueryObject;
import cn.wolfcode.crm.service.IAttendanceService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Administrator on 2018/6/12.
 */

@Controller
@RequestMapping("attendance")
public class AttendanceController {

    @Autowired
    private IAttendanceService attendanceService;

    @RequestMapping("view")
    @RequiresPermissions(value = {"attendance:view", "考勤页面"}, logical = Logical.OR)
    public String view() {
        return "attendance";
    }


    @RequestMapping("query")
    @ResponseBody
    @RequiresPermissions(value = {"attendance:query", "考勤列表"}, logical = Logical.OR)
    public PageResult query(AttendanceQueryObject qo) {
        System.out.println("555555555");
        return attendanceService.query(qo);
    }


    @RequestMapping("saveUp")
    @ResponseBody
    public JsonResult save() {
        try {
            attendanceService.saveUp();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.mark(e.getMessage());
        }
            return JsonResult.success("签到成功");
    }

    @RequestMapping("saveNext")
    @ResponseBody
    public JsonResult saveNext() {
        try {
            attendanceService.saveNext();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.mark(e.getMessage());
        }
        return JsonResult.success("签退成功");
    }

}
